home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1998 April / MACPOWER-1998-04.ISO.7z / MACPOWER-1998-04.ISO / Shareware Paradise / Tabler.091.sit / Tabler 0.9.1 / source code / Tabler.App.c < prev    next >
C/C++ Source or Header  |  1996-11-02  |  4KB  |  166 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * Tabler.App.c
  4.  *--------------------------------------------------------------
  5.  *    Application verion of Tabler
  6.  *--------------------------------------------------------------
  7.  */
  8.  
  9. /* System Include Headers */
  10. #include <Types.h>
  11. #include <Memory.h>
  12. #include <Events.h>
  13. #include <AppleEvents.h>
  14. #include <Scrap.h>
  15. #include <Resources.h>
  16. #include <Files.h>
  17. #include <Sound.h>
  18. #include <Errors.h>
  19.  
  20. /* Project Include Header */
  21. #include "Tabler.h"
  22.  
  23. /* Static functions only used in this source */
  24. static void InitMacintoshToolbox(void);
  25.  
  26. Boolean    gDone = false;
  27.  
  28. /* Implementation */
  29. /*
  30.  *--------------------------------------------------------------
  31.  * main
  32.  *--------------------------------------------------------------
  33.  *    main is main, cannot be whatever else.
  34.  *--------------------------------------------------------------
  35.  */
  36. void main(void)
  37. {
  38.     OSErr    result;
  39.  
  40.     InitMacintoshToolbox();
  41.  
  42.     PlayAClick();
  43.  
  44.     if (SetUpMyAppleEvent()) {
  45.         do {
  46.             EventRecord    anEvent;
  47.             if (WaitNextEvent(highLevelEventMask, &anEvent, -1, nil)) {
  48.                 if (anEvent.what == kHighLevelEvent) {
  49.                     result = AEProcessAppleEvent(&anEvent);
  50.                 }
  51.             }
  52.         } while (gDone == false);
  53.         RemoveMyAppleEvent();
  54.     } else {
  55.         result = ConvertScrap();
  56.     }
  57.     if (result != noErr) {
  58.         SysBeep(20);
  59.     }
  60. }
  61. /*
  62.  *--------------------------------------------------------------
  63.  * InitMacintoshToolbox
  64.  *--------------------------------------------------------------
  65.  *    standard intialization
  66.  *--------------------------------------------------------------
  67.  */
  68. static void InitMacintoshToolbox(void)
  69. {
  70.     MaxApplZone();
  71.     MoreMasters();
  72.  
  73.     InitGraf(&qd.thePort);
  74.     InitFonts();
  75.     InitWindows();
  76.     InitMenus();
  77.     TEInit();
  78.     InitDialogs(0); 
  79.     InitCursor();
  80.     FlushEvents(everyEvent, 0);
  81. }
  82. /*
  83.  *--------------------------------------------------------------
  84.  * OpenSourceDoc
  85.  *--------------------------------------------------------------
  86.  *    open a text file and copy its contents to the scrap
  87.  *--------------------------------------------------------------
  88.  */
  89. OSErr OpenSourceDoc(const FSSpec *theSpec)
  90. {
  91.     FInfo    aDocInfo;
  92.     Handle    textHandle = nil;
  93.     long    textSize = 0;
  94.     short    fRefNum;
  95.     OSErr    result;
  96.  
  97.     result = FSpGetFInfo(theSpec, &aDocInfo);
  98.     if (result == noErr) {
  99.         if (aDocInfo.fdType == 'TEXT') {
  100.             result = FSpOpenDF(theSpec, fsRdPerm, &fRefNum);
  101.             if (result == noErr) {
  102.                 result = GetEOF(fRefNum, &textSize);
  103.                 if (result == noErr) {
  104.                     textHandle = NewHandle(textSize);
  105.                     if (textHandle != nil) {
  106.                         HLock(textHandle);
  107.                         result = FSRead(fRefNum, &textSize, *textHandle);
  108.                         if (result == noErr) {
  109.                             ZeroScrap();
  110.                             result = (OSErr)PutScrap(textSize, 'TEXT', *textHandle);
  111.                             DisposeHandle(textHandle);
  112.                             textHandle = nil;
  113.                             if (result == noErr) {
  114.                                 result = ConvertScrap();
  115.                             }
  116.                         }
  117.                         if (textHandle != nil) {
  118.                             DisposeHandle(textHandle);
  119.                         }
  120.                     } else {
  121.                         result = MemError();
  122.                     }
  123.                 }
  124.                 FSClose(fRefNum);
  125.             }
  126.         } else if (aDocInfo.fdType == 'clpt') {
  127.             short    saveFRef = CurResFile();
  128.             SetResLoad(false);
  129.             fRefNum = FSpOpenResFile(theSpec, fsRdPerm);
  130.             result = ResError();
  131.             SetResLoad(true);
  132.             if (result == noErr) {
  133.                 UseResFile(fRefNum);
  134.                 textHandle = Get1Resource('TEXT', 256);
  135.                 if (textHandle != nil) {
  136.                     HLock(textHandle);
  137.                     ZeroScrap();
  138.                     textSize = GetHandleSize(textHandle);
  139.                     result = (OSErr)PutScrap(textSize, 'TEXT', *textHandle);
  140.                     HUnlock(textHandle);
  141.                     ReleaseResource(textHandle);
  142.                     if (result == noErr) {
  143.                         result = ConvertScrap();
  144.                     }
  145.                 } else {
  146.                     result = resNotFound;
  147.                 }
  148.                 CloseResFile(fRefNum);
  149.             }
  150.             UseResFile(saveFRef);
  151.         }
  152.     }
  153.     return result;
  154. }
  155. /*
  156.  *--------------------------------------------------------------
  157.  * SoundMyClick
  158.  *--------------------------------------------------------------
  159.  *    Application version of playing a click sound
  160.  *--------------------------------------------------------------
  161.  */
  162. void SoundMyClick(void)
  163. {
  164.     PlayAClick();
  165. }
  166. /* end of Tabler.App.c */